package main;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ro.ubbcluj.cs.bibliospringee.backend.model.Author;
import ro.ubbcluj.cs.bibliospringee.backend.service.AuthorService;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public class MainClass
{
    public static void main(String... args)
    {
        final Logger logger = LoggerFactory.getLogger(MainClass.class);

        try
        {
            logger.info("Main class started!");
            System.out.println("Main class started!");

            final InitialContext initialContext = new InitialContext();
            logger.debug("InitialContext initialized");
            System.out.println("InitialContext initialized");

            final AuthorService authorService = (AuthorService) initialContext.lookup("java:global/bibliospringee-server/bibliospringee-backend-1.0-SNAPSHOT/AuthorService");
            logger.debug("AuthorService accessed");
            System.out.println("AuthorService accessed");

            final Author author = new Author("Simon", "Karoly");
            authorService.insertAuthor(author);
            logger.info("New author inserted");
            System.out.println("New author inserted");
        }
        catch (final NamingException e)
        {
            logger.error("Could not access the AuthorService! ", e);
            e.printStackTrace();
        }
    }
}

